<?php
/**
* Model Class
*
* @author Guillermo Landín
* @link
*/ 

class Aboutmodel extends Model {

    function __construct()
    {
        parent::Model();
        
        $this->CI =& get_instance(); 
    }
    
    function get_about_headlines(){
    
         $this->db->select('id_About as id, Title_About as title')
                ->from('about')
                ->where('id_About !=', ABOUT_DEFAULT_ID)
                ->order_by('id_About');            

        $query = $this->db->get();

        return $query->result_array();
    
    }

    function get_content($id = FALSE){

         $this->db->select('id_About as id, Introduction_About as intro, Description_About as text')
                ->from('about');
                
         if ($id !== FALSE)
            $this->db->where('id_About',$id);            
         else 
            $this->db->where('id_About',ABOUT_DEFAULT_ID);

        $query = $this->db->get();

        return $query->row_array();

    }

    function get_all_content(){

         $this->db->select('id_About as id, Title_About as title, Description_About as text')
                ->from('about');
                
        $query = $this->db->get();

        return $query->result_array();

    }


/***********************************
*   Backoffice functions
***********************************/

    //returns the list of about
    function admin_get_list($fields='*'){
    
        $this->db->select($fields)
                ->from('about')
                ->order_by('id_About');  

        $query = $this->db->get();

        $result = $query->result_array();
                                 
        return $result;

    }  
    public function admin_get_item($id=FALSE, $fields='*'){

        $this->db->select($fields)
                ->from('about')       
                ->where('id_About', $id);  
        
        $query = $this->db->get();
        return $query->row_array();

    }  
    public function admin_update($id=FALSE, $data=array()){

        $this->db->where('id_About', $id)
                ->update('about', $data); 

    }                      
    public function admin_insert($data=array()){

        //$data["id_About"] = uniqid();
        $this->db->insert('about', $data); 
        return $this->db->insert_id();

    }  
    public function admin_delete($id=FALSE){

        $this->db->where('id_About', $id);
        $this->db->delete('about'); 

    } 
    public function is_duplicated($field, $value, $id=FALSE)
    {
    
        $this->db->select('count(1) as counter')
                ->from('about')
                ->where($field, $value);        
        if($id!==FALSE) $this->db->where('id_About !=', $id);
    
        $query = $this->db->get();
        $row = $query->row_array();
        if($row == NULL)
            return FALSE;
        
        if($row["counter"] > 0){
            return TRUE;
        }else{
            return FALSE;
        }

    } 

    
}
